<?php
/**
 * https://gitee.com/Mao02
 * http://www.dazhetu.cn/
 * jay_fun 410136330@qq.com
 * Date: 2018/10/13 0013
 * Time: 20:56
 */

namespace app\admin\controller\content;

use app\common\controller\BasicAdmin;
use app\common\facade\Music163;
use app\common\model\content\Music as MusicModel;
use think\facade\Request;

/**
 * @title 音乐管理
 * Class Music
 * @package app\admin\controller
 */
class Music extends BasicAdmin
{
    protected $table = "content_music";

    /**
     * @title 歌曲列表页
     * @return mixed
     * @throws \think\Exception\DbException
     */
    public function index()
    {
        $music = MusicModel::all();

        $this->assign('list',$music);
        return $this->fetch();
    }

    /**
     * @title 添加歌曲
     * @return array|mixed|null|\PDOStatement|string|\think\Model
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function add()
    {
        return $this->_form('', 'form');
    }

    /**
     * 添加前置
     * @param $data
     */
    protected function _add_form_before(&$data){
        if (Request::isPost()){
            $music_id = $data['music_id'];
            unset($data['music_id']);

            $data = Music163::getMusic($music_id);
        }
    }

    /**
     * @title 删除歌曲
     */
    public function del()
    {
        $id = Request::post('ids',false);
        !$id && $this->error("缺少参数！");

        $res = MusicModel::destroy($id);
        if (!$res){
            $this->error("操作失败！");
        }
        $this->success("操作成功！");
    }
}